﻿using AnlianCommon.Common.Domains.BankCustomers;
using AnlianCommon.Common.DTO;
using AnlianCommon.Common.Infrastructure.IRepository;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace SheepCommon.API.Vendors
{
    public class VendorcontactBackFillHandler : IRequestHandler<VendorcontactBackFillCommand, Result>
    {
        private readonly IBaseRepository<Vendorcontact> _vendorcontactRepository;

        public VendorcontactBackFillHandler(IBaseRepository<Vendorcontact> vendorcontactRepository)
        {
            _vendorcontactRepository = vendorcontactRepository;
        }
        /// <summary>
        /// 客户联系反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(VendorcontactBackFillCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var vendorcontactById = await (await _vendorcontactRepository.GetAll()).FirstOrDefaultAsync();
                if (vendorcontactById != null)
                {
                    result.Data = vendorcontactById;
                }

            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
